package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallShopCheckMapper;
import org.linlinjava.litemall.db.domain.LitemallShopCheck;
import org.linlinjava.litemall.db.domain.LitemallShopCheckExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class LitemallShopCheckService {
	@Resource
	private LitemallShopCheckMapper litemallShopCheckMapper;

	public List<LitemallShopCheck> querySelective(Integer shopId, String checkNo, LocalDateTime startDate
			, LocalDateTime endDate,String shopName, Integer page, Integer limit, String sort, String order) {

		LitemallShopCheckExample example = new LitemallShopCheckExample();
		LitemallShopCheckExample.Criteria criteria = example.createCriteria();
		if (null != shopId) {
			criteria.andShopIdEqualTo(shopId);
		}
		if (!StringUtils.isEmpty(checkNo)) {
			criteria.andCheckNoLike("%" + checkNo + "%");
		}
		if (null != startDate) {
			criteria.andCheckTimeGreaterThanOrEqualTo(startDate);
		}
		if (null != endDate ) {
			criteria.andCheckTimeLessThanOrEqualTo(endDate);
		}
		if(shopName!=null){
			criteria.andShopNameEqualTo(shopName);
		}
		criteria.andDeletedEqualTo(false);
		if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
			example.setOrderByClause(sort + " " + order);
		}
		////PageHelper.startPage(page, limit);
		return litemallShopCheckMapper.selectByExampleSelective(example);
	}

	public int create(LitemallShopCheck shopCheck) {
		shopCheck.setAddTime(LocalDateTime.now());
        return litemallShopCheckMapper.insertSelective(shopCheck);
    }

    public LitemallShopCheck findById(Integer id) {
        return litemallShopCheckMapper.selectByPrimaryKey(id);
    }

}
